﻿using AutoMapper;
using MediatR;
using S.Authorization.API.Application.Command.OrganizationCommand;
using S.Authorization.Domain.Model.Organization;
using S.Authorization.Infrastructure.Interface.Organization;

namespace S.Authorization.API.Application.CommandHandlers.OrganizationCommandHandler
{
    public class DepartmentCreateCommandHandler : IRequestHandler<DepartmentCreateCommand, bool>
    {
        private readonly IDepartmentRepository department;
        private readonly IMapper mapper;
        public DepartmentCreateCommandHandler(IDepartmentRepository _department, IMapper _mapper)
        {
            department = _department;
            mapper = _mapper;
        }
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(DepartmentCreateCommand request, CancellationToken cancellationToken)
        {
            request.CreateTime = DateTime.Now;
            DepartmentModel columns = mapper.Map<DepartmentModel>(request);
            return await department.AddAsync(columns);
        }
    }
}
